package com.jiuyin.dianjing.api.interceptor;

import com.jiuyin.dianjing.util.NetworkUtil;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import static com.jiuyin.dianjing.api.constant.ApiConstant.CACHE_DAYS;

/**
 * Description:
 * File: HttpCacheInterceptor.java
 * Author: Administrator
 * Create: 2018/07/30 10:27
 *
 * @author Administrator
 */
public class HttpCacheInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        okhttp3.Response response = chain.proceed(request);
        if (NetworkUtil.isConnected()) {
            return response.newBuilder()
                    .removeHeader("Pragma")
                    .header("Cache-Control", "public, ,max-age=" + CACHE_DAYS)
                    .build();
        }
        return response;
    }
}
